import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'
let _this = null
class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'sopName',
        minWidth: 150,
        header: {
          filter: {
            title: '加/减分项',
            key: 'sopName',
            placeholder: '请输入加/减分项',
            input: {}
          }
        }
      },

      {
        field: 'taskClass',
        minWidth: 150,
        header: {
          filter: {
            title: '所属分类',
            key: 'taskClass',
            placeholder: '请选择任务分类',

            select: {
              options: dt.dictInfo().sopTaskClass,
              filterable: true
            }
          }
        },
        slots: {
          default: (params, h) => {
            return dt.dictInfo().__value('sopTaskClass', params.row.taskClass)
          }
        }
      },

      {
        field: 'leaderMsg',
        minWidth: 150,
        title: '任务责任人节点'
      },
      {
        field: 'taskScope',
        minWidth: 150,
        header: {
          filter: {
            title: '任务责任人范围',
            key: 'taskScope',
            placeholder: '请选择任务责任人范围',

            select: {
              options: [
                { key: 1, value: '所有人员' },
                { key: 2, value: '指定人员' }
              ],
              filterable: true
            }
          }
        },
        slots: {
          default: (params, h) => {
            return [
              h('div', params.row.taskScope == 1 ? '所有人员' : '指定人员')
            ]
          }
        }
      },
      {
        field: 'pointType',
        minWidth: 150,
        header: {
          filter: {
            title: '任务节点类型',
            key: 'pointType',
            placeholder: '请选择任务节点类型',

            select: {
              options: [
                { key: 1, value: '单节点任务' },
                { key: 2, value: '多节点任务' }
              ]
            }
          }
        },
        slots: {
          default: (params, h) => {
            return [
              h('div', params.row.pointType == 1 ? '单节点任务' : '多节点任务')
            ]
          }
        }
      },

      {
        field: 'taskDeductType',
        minWidth: 250,
        header: {
          filter: {
            title: '任务加减分类型',
            key: 'taskDeductType',
            placeholder: '请选择任务加减分类型',

            select: {
              options: dt.dictInfo().sopTaskDeductType,
              filterable: true
            }
          }
        },
        slots: {
          default: (params, h) => {
            return dt
              .dictInfo()
              .__value('sopTaskDeductType', params.row.taskDeductType)
          }
        }
      },
      {
        field: 'isTaskAssess',
        minWidth: 150,
        header: {
          filter: {
            title: '是否生成任务',
            key: 'isTaskAssess',
            placeholder: '请选择是否生成任务',

            select: {
              options: [
                { key: 1, value: '是' },
                { key: 0, value: '否' }
              ],
              filterable: true
            }
          }
        },
        slots: {
          default: (params, h) => {
            return [
              h(
                'div',
                params.row.type == 1
                  ? params.row.isTaskAssess == true
                    ? '是'
                    : '否'
                  : '-'
              )
            ]
          }
        }
      },
      {
        field: 'isAssess',
        minWidth: 150,
        header: {
          filter: {
            title: '是否执行加/减分',
            key: 'isAssess',
            placeholder: '请选择是否执行加/减分',
            select: {
              options: [
                { key: 1, value: '是' },
                { key: 0, value: '否' }
              ]
            }
          }
        },
        slots: {
          default: (params, h) => {
            return [h('div', params.row.isAssess == true ? '是' : '否')]
          }
        }
      },
      {
        field: 'updateTime',
        title: '最近编辑时间',
        minWidth: 150
      },

      {
        title: '操作人',
        field: 'updater',
        minWidth: 150
      },

      {
        title: '操作',
        fixed: 'right',
        width: 300,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = []
            btns.push({
              title: '任务开关',
              event: 'checkFun1',
              data: params.row
            })
            btns.push({
              title: '任务节点',
              event: 'checkFun2',
              data: params.row
            })
            btns.push({
              title: params.row.backRole ? '责任人' : '',
              event: params.row.backRole ? 'checkFun3' : '',
              data: params.row
            })
            btns.push({
              title: '扣分值',
              event: 'checkFun4',
              data: params.row
            })
            btns.push({
              title: '同步',
              event: 'checkFun5',
              data: params.row
            })
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

export default Column
